<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <Header></Header>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'"><!--判断是否被折叠-->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 -->

        <el-menu background-color="#F8F8F8" text-color="#3c3c3c" active-text-color="#00ac84" unique-opened :collapse="isCollapse"
          :collapse-transition="false" router :default-active="activePath">
          <!-- 一级菜单 -->
          <!--1、个人中心主页 个人信息展示-->
          <el-menu-item index="/myInfo">
            <!-- 一级菜单的模板区域 -->
              <!-- 图标 -->
              <i class="el-icon-user-solid"></i>
              <!-- 文本 -->
              <span slot="title"@click="saveNavState('/myInfo')" class="menuFont">我的资料</span>
          </el-menu-item>
          <!--我的仓库-->
          <el-menu-item index="/myHouseList">
              <!-- 图标 -->
              <i class="el-icon-s-home"></i>
              <!-- 文本 -->
              <span slot="title" @click="saveNavState('/myHouseList')" class="menuFont">我的仓库</span>
          </el-menu-item>

          <!--3、发布房源-->
          <el-menu-item index="/addHouse">
              <!-- 图标 -->
              <i class="el-icon-edit-outline"></i>
              <!-- 文本 -->
              <span slot="title" @click="saveNavState('/addHouse')" class="menuFont">发布房源</span>
          </el-menu-item>
          <!--4.修改密码-->
          <el-menu-item index="">
              <!-- 图标 -->
              <i class="el-icon-lock"></i>
              <!-- 文本 -->
              <span slot="title" class="menuFont">修改密码</span>
          </el-menu-item>



        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import Header from '../../components/main/Header.vue' //头部

export default {
  components:{
    Header
  },
  data () {
    return {
      // 是否折叠
      isCollapse: false,
      // 被激活的链接地址
      activePath: ''
    }
  },
  created () {
    // 查询导航菜单
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    // 点击按钮，切换菜单的折叠与展开
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    },
    // 保存链接的激活状态
    saveNavState (activePath) {
      //console.log(activePath);
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style scoped>
  /*最外部*/
  home-container {
    height: 100%;
  }
/*头部*/
  .el-header {
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;
  }

  .headerdiv {
    display: flex;
    align-items: center;
  }

  .headerdiv span {
    margin-left: 15px;
  }

  .headerdiv img {
    width: 80px;
    height: 60px;
  }
/*左侧栏*/
  .el-aside {
    background-color: #fff;
  }

  .el-aside .el-menu {
    border-right: none;
  }
/*主体区*/
  .el-main {
    background-color: #fff;
  }

  .iconfont {
    margin-right: 10px;
  }
/*折叠按钮*/
  .toggle-button {
    background-color: #00AC84;
    font-size: 14px;
    line-height: 26px;
    color: #F8F8F8;
    text-align: center;
    letter-spacing:3px;
    cursor: pointer;
  }

/*菜单栏*/
.menuFont{
  font-size: 15px;
  letter-spacing:1px;
}


</style>
